﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.ts_goods>" %>

<!DOCTYPE html>

<html>
<head id="Head1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>操作</title>
    <script src="<%: Url.Content("~/Scripts/jquery.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/JScriptIndex.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/jquery.easyui.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Res/easyui/locale/easyui-lang-zh_CN.js") %>" type="text/javascript"></script>
    <link href="<%: Url.Content("~/Res/easyui/themes/default/easyui.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Res/easyui/themes/icon.css") %>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Content/StyleSheet.css") %>" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript">
        $(function () {

            $('#flexigridData').datagrid({
                title: '物品目录', //列表的标题
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                collapsible: true,
                url: '../ts_goods/GetData?id=' + $('#tbhid').val(), //获取数据的url
                sortName: 'Id',
                sortOrder: 'desc',
                idField: 'Id',

                toolbar: [

                     {
                         text: '详细',
                         iconCls: 'icon-search',
                         handler: function () {
                             return getView();
                         }
                     }, {
                         text: '创建',
                         iconCls: 'icon-add',
                         handler: function () {
                             return flexiCreate();
                         }
                     }, {
                         text: '删除',
                         iconCls: 'icon-remove',
                         handler: function () {
                             return flexiDelete();
                         }
                     }, {
                         text: '修改',
                         iconCls: 'icon-edit',
                         handler: function () {
                             return flexiModify();
                         }
                     }],
                columns: [[
                      { field: 'i_sign', title: '<%: Html.LabelFor(model => model.i_sign) %>', width: 60 }
                	, { field: 'c_code', title: '<%: Html.LabelFor(model => model.c_code) %>', width: 80 }
				 	, { field: 'c_desc', title: '<%: Html.LabelFor(model => model.c_desc) %>', width: 80 }
					, { field: 'c_model', title: '<%: Html.LabelFor(model => model.c_model) %>', width: 80 }
					, { field: 'c_unit', title: '<%: Html.LabelFor(model => model.c_unit) %>', width: 80 }
					, { field: 'c_class', title: '<%: Html.LabelFor(model => model.c_class) %>', width: 80 }
					, { field: 'c_class1', title: '<%: Html.LabelFor(model => model.c_class1) %>', width: 52, hidden: true }
					, { field: 'f_pricelast', title: '<%: Html.LabelFor(model => model.f_pricelast) %>', width: 52, hidden: true }
					, { field: 'f_upper', title: '<%: Html.LabelFor(model => model.f_upper) %>', width: 60 }
					, { field: 'f_lower', title: '<%: Html.LabelFor(model => model.f_lower) %>', width: 60 }
					, { field: 'c_py', title: '<%: Html.LabelFor(model => model.c_py) %>', width: 52, hidden: true }
					, { field: 'c_comment', title: '<%: Html.LabelFor(model => model.c_comment) %>', width: 52, hidden: true }
					, { field: 'c_vendor', title: '<%: Html.LabelFor(model => model.c_vendor) %>', width: 90 }
					, { field: 'c_base', title: '<%: Html.LabelFor(model => model.c_base) %>', width: 90 }
                ]],
                pagination: true,
                rownumbers: true

            });

            var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }


            $('#myTree').tree({
                url: '../ts_goodsclass/GetGoodsTree',
                onClick: function (node) {
                    if (node != null && node.id != null && node.id != "undefined") {
                        if (node.iconCls != null) {//&& node.iconCls == 'icon-ok'
                            $("#hidtreeid").val(''); 
                            $('#tbhid').val(node.text);
                            $("#flexigridData").datagrid("load"); //根目录刷新  
                        } else {
                            $("#hidtreeid").val(node.id); 
                            $('#tbhid').val(node.text);
                            $("#flexigridData").datagrid("load", { id: node.text }); //子节点刷新
                        }

                    }
                },
                onBeforeLoad: function (node, param) {
                    if (node) {
                        param.parentid = node.id;
                    }
                }
            });

        });

        //“查询”按钮，弹出查询框
        function flexiQuery() {

            //将查询条件按照分隔符拼接成字符串
            var search = "";
            $('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
                search = search + this.id + "&" + this.value + "^";
            });
            //执行查询                        
            $('#flexigridData').datagrid('reload', { search: search });
        };

        //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
        function flexiSelect() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].c_desc);
            }
            arr.push("^");
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].c_code);
            }
            //主键列和显示列之间用 ^ 分割   每一项用 , 分割
            if (arr.length > 0) {//一条数据和多于一条
                returnParent(arr.join("&")); //每一项用 & 分割
            }
        }
        //导航到查看详细的按钮
        function getView() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "../ts_goods/Details/" + arr[0].Id;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        }
        //导航到创建的按钮
        function flexiCreate() {

            window.location.href = "../ts_goods/Create";
            return false;
        }

        //导航到修改的按钮
        function flexiModify() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "../ts_goods/Edit/" + arr[0].Id;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        };

        //删除的按钮
        function flexiDelete() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].Id);
            }

            $.messager.confirm('操作提示', "确认删除这 " + arr.length + " 项吗？", function (r) {
                if (r) {
                    $.post("../ts_goods/Delete", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据

                            $.messager.alert('操作提示', '删除成功!', 'info');
                            $("#flexigridData").datagrid("reload");
                            $("#flexigridData").datagrid("clearSelections");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });
        };

    </script>
</head>
<body class="easyui-layout">
    <div region="west" split="true" title="物品分类" style="width: 180px;">
        <ul id="myTree">
        </ul>
    </div>
    <div id="content" region="center" fit="true" title="目录" style="padding: 5px;">
        <table id="flexigridData">
        </table>
    </div>
   <input type="hidden" id="tbhid" />
    <input id="hidtreeid" type="hidden" />
    <input id="SysMenuIdOld" type="hidden" />
</body>
</html>
